﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Compiler.TableOfSymbols.Types
{
    public class TypeVariable : BaseType
    {
        private TypeValue maxLowerType;
        private TypeValue minUpperType;

        public TypeValue MaxLowerType
        {
            get { return maxLowerType; }
            set 
            {
                if (value == null)
                    throw new ArgumentNullException("MaxLowerType can not be null");
                this.maxLowerType = value; 
            }
        }
        public TypeValue MinUpperType
        {
            get { return minUpperType; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("MinUpperType can not be null");
                this.minUpperType = value;
            }
        }

        public TypeVariable(string name)
            : this(name, new BottomType(), new TopType())
        { }

        public TypeVariable(string name, TypeValue maxLowerType, TypeValue minUpperType)
            : base(name)
        {
            if (maxLowerType == null)
                throw new ArgumentNullException("maxLowerType can not be null");
            if (minUpperType == null)
                throw new ArgumentNullException("minUpperType can not be null");
            this.maxLowerType = maxLowerType;
            this.minUpperType = minUpperType;
        }

        public override string ToString()
        {
            return String.Format("type_var[{0}]", Name);
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode() - 2081;
        }

        protected override void _SetCategory()
        {
            this.category = SymbolTableDataCategory.TYPE;
        }

        public override bool IsTypeVariable
        {
            get { return true; }
        }
    }
}
